﻿#region References
using System;

#endregion

namespace App_Code.Objects
{
    /// <summary>
    /// Summary description for ConnectionProfileDTO
    /// </summary>
    public class ConnectionProfileDTO
    {
        #region Fields

        private readonly Guid _connectionId = Guid.NewGuid();
        #endregion

        #region Properties
        public bool IsLocalServer { get; set; }

        public bool UseCompression { get; set; }

        public string Host { get; set; }

        public int Port { get; set; }

        public string Username { get; set; }

        public string Password { get; set; }

        public int? Id { get; set; }

        public Guid ConnectionId
        {
            get
            {
                return _connectionId;
            }
        }

        #endregion

        #region Overriden methods
        /// <summary>
        ///     Assumes two connections to be equal when they have same settings, but different Id
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public override bool Equals(object obj)
        {
            var conn = (obj as ConnectionProfileDTO);

            if (conn == null)
                return false;

            return (
                (conn.Host ?? String.Empty) == (Host ?? String.Empty) &&
                (conn.Username ?? String.Empty) == (Username ?? String.Empty) &&
                conn.IsLocalServer == IsLocalServer &&
                conn.Port == Port &&
                conn.UseCompression == UseCompression &&
                (conn.Password ?? string.Empty) == (Password ?? string.Empty));
        }

        // overriden to get rid of warning
        public override int GetHashCode()
        {
            return base.GetHashCode();
        }

        #endregion

        #region Public methods

        public ConnectionProfileDTO GetCopy()
        {
            return (ConnectionProfileDTO)this.MemberwiseClone();
        }
        #endregion
    }
}